unit RemoveResultsGui;

interface

uses
  InventionCalc, Results, Items,

  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TfrmRemoveResults = class(TForm)
    btnRemove: TButton;
    btnCancel: TButton;
    gbRemoveResults: TGroupBox;
    lblItem: TLabel;
    lblConfiguration: TLabel;
    lblSuccesses: TLabel;
    lblFailures: TLabel;
    lblResultItem: TLabel;
    lblResultConfiguration: TLabel;
    lblResultSuccesses: TLabel;
    lblResultFaillures: TLabel;
    lblRemoveSuccesses: TLabel;
    lblRemoveFailures: TLabel;
    edtRemoveSuccesses: TEdit;
    edtRemoveFailures: TEdit;
    chkRemoveConfiguration: TCheckBox;
    procedure btnCancelClick(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure btnRemoveClick(Sender: TObject);
  private
    inventionCalc: TInventionCalc;
    _item: TNewItem;
    _configuration: TConfiguration;
    _successes: Integer;
    _failures: Integer;

    _canclose: Boolean;
  public
    constructor Create(AOwner: TComponent; invCalc: TInventionCalc; item: TNewitem; configuration: TConfiguration; successes, failures: Integer); reintroduce;
  end;

var
  frmRemoveResults: TfrmRemoveResults;

implementation

{$R *.dfm}

constructor TfrmRemoveResults.Create(AOwner: TComponent; invCalc: TInventionCalc; item: TNewitem; configuration: TConfiguration; successes, failures: Integer);
begin
  inherited Create(AOwner);
  inventionCalc := invCalc;
  _item := item;
  _configuration := configuration;
  _successes := successes;
  _failures := failures;

  lblResultItem.Caption := _item.Name;
  lblResultConfiguration.Caption := _configuration.Name;
  lblResultSuccesses.Caption := IntToStr(_successes);
  lblResultFaillures.Caption := IntToStr(_failures);
end;

procedure TfrmRemoveResults.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);
begin
  CanClose := _canclose;
end;

procedure TfrmRemoveResults.btnRemoveClick(Sender: TObject);
var
  i: Integer;
begin
  _canclose := true;
  edtRemoveSuccesses.Color := clWindow;
  edtRemoveFailures.Color := clWindow;
  if ((not TryStrToInt(edtRemoveSuccesses.Text, i)) or (i > _successes))then begin
    edtRemoveSuccesses.Color := clRed;
    _canclose := false;
  end;
  if ((not TryStrToInt(edtRemoveFailures.Text, i)) or (i > _failures))then begin
    edtRemoveFailures.Color := clRed;
    _canclose := false;
  end;
  if (_canclose) then begin
    inventionCalc.Results.RemoveResult(_item, _configuration, StrToInt(edtRemoveSuccesses.Text), StrToInt(edtRemoveFailures.Text), chkRemoveConfiguration.Checked);
  end;
end;

procedure TfrmRemoveResults.btnCancelClick(Sender: TObject);
begin
  _canclose := true;
end;

end.
